//
//  PowerUpSpeedBoost.m
//  MessangerSkeleton
//
//  Created by User-23 on 4/27/14.
//  Copyright (c) 2014 IOTrainingCamp. All rights reserved.
//

#import "PowerUpSpeedBoost.h"
#import "cocos2d.h"
#import "Configuration.h"

@interface PowerUpSpeedBoost ()

@property GameObjectType* type;
@end

@implementation PowerUpSpeedBoost

- (instancetype)init
{
    self = [super initWithSpriteFrame:[CCSpriteFrame frameWithImageNamed:@"PoowerUpSpeedBoost.png"]];
    if (self) {
        
        self.type = kPowerUpTypeSpeed;
        
        //TODO: should be loaded from a plist and this should be separate method common for all sprites
        int num = 19;
        CGPoint* powerUpSpeedBoost = malloc(sizeof(CGPoint)*num);
        
        powerUpSpeedBoost[0] = ccp(-30.5f, 83.9f);
        powerUpSpeedBoost[1] = ccp(-29.8f, 57.5f);
        powerUpSpeedBoost[2] = ccp(-26.7f, 26.9f);
        powerUpSpeedBoost[3] = ccp(-23.5f, 9.9f);
        powerUpSpeedBoost[4] = ccp(-23.5f, 0.9f);
        powerUpSpeedBoost[5] = ccp(-9.4f, -0.6f);
        powerUpSpeedBoost[6] = ccp(-39.8f, -82.6f);
        powerUpSpeedBoost[7] = ccp(-44.8f, -96.9f);
        powerUpSpeedBoost[8] = ccp(-39.2f, -98.0f);
        powerUpSpeedBoost[9] = ccp(-33.8f, -94.5f);
        powerUpSpeedBoost[10] = ccp(60.1f, 25.8f);
        powerUpSpeedBoost[11] = ccp(61.4f, 34.0f);
        powerUpSpeedBoost[12] = ccp(20.5f, 32.8f);
        powerUpSpeedBoost[13] = ccp(50.3f, 91.1f);
        powerUpSpeedBoost[14] = ccp(51.6f, 100.1f);
        powerUpSpeedBoost[15] = ccp(46.4f, 101.4f);
        powerUpSpeedBoost[16] = ccp(-27.0f, 90.0f);
        powerUpSpeedBoost[17] = ccp(-31.5f, 87.7f);
        powerUpSpeedBoost[18] = ccp(-31.5f, 73.8f);
        
        
        CGPoint offset = ccp(155, 150);
        
        for(int i=0; i< num; i++)
        {
            powerUpSpeedBoost[i] = ccp(powerUpSpeedBoost[i].x + offset.x, powerUpSpeedBoost[i].y + offset.y);
        }
        
        
        self.physicsBody = [CCPhysicsBody bodyWithPolygonFromPoints:powerUpSpeedBoost count:num cornerRadius:20];
        
        free(powerUpSpeedBoost);
        self.scale = 0.20;
        self.physicsBody.sensor = YES;
        self.physicsBody.collisionType = @"powerUpSpeedBoost";
    }
    return self;
}

-(void)update:(CCTime)delta
{
    if(self.position.x + self.boundingBox.size.width < 0)
        [self removeFromParentAndCleanup:YES];
}

@end
